#include <bits/stdc++.h>
using namespace std;
const int N = 510, M = N * N;
int n, m;
char g[N][N];
int dist[N][N];
bool st[N][N];

int bfs() {
  deque<pair<int, int>> q;
  memset(st, 0, sizeof st);
  memset(dist, 0x3f, sizeof dist);
  dist[0][0] = 0;
  char cs[5] = "\\/\\/";
  int dx[4] = {-1, -1, 1, 1}, dy[4] = {-1, 1, 1, -1};
  int ix[4] = {-1, -1, 0, 0}, iy[4] = {-1, 0, 0, -1};

  q.emplace_front(0, 0);

  while (q.size()) {
    auto [x, y] = q.front();
    q.pop_front();

    if (x == n && y == m) return dist[n][m];
    if (st[x][y]) continue;
    for (int i = 0; i < 4; ++i) {
      int a = x + dx[i], b = y + dy[i];
      if (a < 0 || a > n || b < 0 || b > m) continue;
      int ga = x + ix[i], gb = y + iy[i];
      int w = (g[ga][gb] != cs[i]);
      int d = dist[x][y] + w;
      if (d < dist[a][b]) {
        dist[a][b] = d;
        if (w)
          q.emplace_back(a, b);
        else
          q.emplace_front(a, b);
      }
    }
  }
  return -1;
}

int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) cin >> g[i];

    if (n + m & 1)
      puts("NO SOLUTION");
    else
      printf("%d\n", bfs());
  }
}
